home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / PNL Libraries / MyGrowZones.p < prev    next >
Encoding:
Text File  |  1994-08-27  |  1.5 KB  |  83 lines  |  [TEXT/PJMM]

  1. unit MyGrowZones;
  2.  
  3. interface
  4.  
  5.     procedure InitGrowZone (size: longInt; alertid: integer);
  6.     procedure FinishGrowZone;
  7.     procedure IdleGrowZone;
  8.     function MemoryCritical: boolean;
  9.     function EnoughSpace (total, contig: longInt): boolean;
  10.  
  11. implementation
  12.  
  13.     var
  14.         gzh: handle;
  15.         gz_size: longINt;
  16.         lastgzh: handle;
  17.         id: integer;
  18.  
  19.     function MyGrowZone (size: longInt): longInt;
  20.         var
  21.             saved_A5, junk: longInt;
  22.     begin
  23.         saved_A5 := SetCurrentA5;
  24.         if gzh <> nil then begin
  25.             MyGrowZone := GetHandleSize(gzh);
  26.             DisposHandle(gzh);
  27.             gzh := nil;
  28.         end
  29.         else begin
  30.             MyGrowZone := 0;
  31.         end;
  32.         junk := SetA5(saved_A5);
  33.     end;
  34.  
  35.     procedure IdleGrowZone;
  36.         var
  37.             t, c: longInt;
  38.             a: integer;
  39.     begin
  40.         if gzh = nil then begin
  41.             gzh := NewHandle(gz_size);
  42.             if (gzh = nil) and (lastgzh <> nil) and (id > 0) then begin
  43.                 SetCursor(arrow);
  44.                 a := StopAlert(id, nil);
  45.             end;
  46.             lastgzh := gzh;
  47.         end;
  48.     end;
  49.  
  50.     function MemoryCritical: boolean;
  51.     begin
  52.         MemoryCritical := gzh = nil;
  53.     end;
  54.  
  55.     function EnoughSpace (total, contig: longInt): boolean;
  56.         var
  57.             t, c: longInt;
  58.     begin
  59.         PurgeSpace(t, c);
  60.         EnoughSpace := not MemoryCritical & (t >= total) & (c >= contig);
  61.     end;
  62.  
  63. {$S Init}
  64.     procedure InitGrowZone (size: longInt; alertid: integer);
  65.     begin
  66.         gz_size := size;
  67.         id := alertid;
  68.         SetGrowZone(@MyGrowZone);
  69.         gzh := nil;
  70.         lastgzh := nil;
  71.         IdleGrowZone;
  72.     end;
  73.  
  74. {$S Term}
  75.     procedure FinishGrowZone;
  76.     begin
  77.         if gzh <> nil then begin
  78.             DisposHandle(gzh);
  79.             gzh := nil;
  80.         end;
  81.     end;
  82.  
  83. end.